package com.sc.nft.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.MallActivityShare;
import com.sc.nft.entity.dto.*;
import com.sc.nft.entity.vo.*;
import com.sc.nft.service.MallActivityService;
import com.sc.nft.service.MallActivityShareService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.math.BigDecimal;

/**
 * <p>
 * 分享购活动 前端控制器
 * </p>
 *
 * @author ligen
 * @since 2023-12-11
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/activity/share")
@Api(tags = "分享购活动模块")
public class MallActivityShareController {

    public final MallActivityShareService mallActivityShareService;
    private final MallActivityService mallActivityService;

    @ApiOperation(value = "分享购活动列表", notes = "分享购活动列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminMallActivitySharePageDTO> activityCouponsPage(@RequestBody AdminMallActivitySharePageVO adminMallActivitySharePageVO) {
        return PageResult.success(mallActivityShareService.getAdminMallActivitySharePageDTO(adminMallActivitySharePageVO));
    }

    @ApiOperation(value = "添加分享购活动", notes = "添加分享购活动", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result add(@Valid @RequestBody EditMallActivityShareVO vo) {
        mallActivityShareService.create(vo);
        return Result.success();
    }

    @ApiOperation(value = "分享购活动详情", notes = "分享购活动详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/details", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<MallActivityShareDetailDTO> details(@RequestBody IdRequest idRequest) {
        MallActivityShareDetailDTO mallActivityShareDetailDTO = mallActivityShareService.getMallActivityShareDetailDTO(idRequest.getId());
        return Result.success(mallActivityShareDetailDTO);
    }

    @ApiOperation(value = "分享购活动上架", notes = "分享购活动上架", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/enable", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result enable(@Valid @RequestBody IdRequest idRequest) {
        mallActivityShareService.enable(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "分享购活动下架", notes = "分享购活动下架", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/disable", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result disable(@Valid @RequestBody IdRequest idRequest) {
        mallActivityShareService.disable(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "分享购活动排序 只传ID 以及 Sort", notes = "分享购活动排序 只传ID 以及 Sort", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateSort", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateSort(@RequestBody EditMallActivityShareVO vo) {
        mallActivityShareService.updateSort(vo.getId(),vo.getSort());
        return Result.success();
    }

    @ApiOperation(value = "可参加分享购的活动商品", notes = "可参加分享购的活动商品", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/canAddProductList", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<ActivityShareProductDTO> getActivityShareCanUseProductDTOPage(@RequestBody ActivityShareCanUseProductVO activityShareCanUseProductVO) {
        return PageResult.success(mallActivityService.getActivityShareCanUseProductDTOPage(new Page(activityShareCanUseProductVO.getPageNo(), activityShareCanUseProductVO.getPageSize()),activityShareCanUseProductVO.getProductName(),activityShareCanUseProductVO.getDaoId()));
    }

    /**
     * 获取分享购团长可得最大收益
     *
     * @param maxRewardPercentageVO
     * @return
     */
    @ApiOperation(value = "获取分享购团长可得最大收益", notes = "获取分享购团长可得最大收益", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/maxRewardPercentage", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<BigDecimal> maxRewardPercentage(@Valid @RequestBody MaxRewardPercentageVO maxRewardPercentageVO) {
        return Result.success(mallActivityShareService.maxRewardPercentage(maxRewardPercentageVO));
    }
}
